package com.hopoke.user.controller;

import com.hopoke.common.domain.Result;
import com.hopoke.user.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "角色管理接口")
@RestController
@RequestMapping("/user/role")
@RequiredArgsConstructor
public class RoleController {

    private final RoleService roleService;

    @ApiOperation("根据用户获取自身以及所有角色")
    @PostMapping("/getAllRoles")
    public Result<Map<String,Object>> getAll(@RequestHeader String token, @RequestBody Long userId) {
        Map<String, Object> map = new HashMap<>();

        map.put("allRoles", roleService.list());
        map.put("userRole", roleService.getRolesByUserId(userId));

        return Result.ok(map);
    }
}
